<template>
    <div>
        <!--新增按钮位置-->
        <div style="position:fixed;z-index:100;width:100%">
            <div style="position:fixed;width:100%;padding: 2px;" class="van-cell--borderless van-contact-card">
                <van-dropdown-menu title="实训选择">
                    <van-dropdown-item v-model="classId" :options="classInfos" @change="changeClass" />
                </van-dropdown-menu>
            </div>
        </div>
        <!--列表展示位置-->
        <div v-show="show == 0">
            <div style="height: 73px"></div>
            <van-steps 
                v-for="(item,index) in tasks"
                direction="vertical" style="border: 1px solid #c20;margin: 5px"
                active="4">
                <van-step>
                  <h3>任务名称</h3>
                  <p>{{item.name}}</p>
                </van-step>
                <van-step>
                  <h3>任务要求</h3>
                  <p>{{item.content}}</p>
                </van-step>
                <van-step>
                  <h3>截止时间</h3>
                  <p>{{item.endTime.substring(0,10)}}</p>
                </van-step>
              </van-steps>
              <!-- <van-cell style="text-align: left;" center title="单元格" value="内容" label="描述信息">
                <van-tag type="primary">111</van-tag>
              </van-cell> -->
              <div style="height: 73px"></div>
        </div>
    </div>
</template>
<script>
import req from '../../request/index'

export default {
    name: '',
    data() {
        return {
            showScore: false,
            show: 0,
            classInfos: [],
            classId: '',
            practiceTitle: '',
            tasks:[],
        };
    },
    methods: {
        getTasksByClassId() {
            req({
                url: "getTasksByTeacherIdAndClassId",
                method: "post",
                data: {
                    relationClassId: this.classId
                }
            }).then(res => {
                this.tasks = res.data.data;
            }).catch(err => {
                console.log(err);
            })
        },
        getShixun(){
            req({
                url: "getShixun",
                method: "post",
                data: {
                    id: this.$store.state.user.id
                }
            }).then(res => {
                if (res.data.code == 0) {
                    var data = res.data.data;
                    this.classId = res.data.data[0].id;
                    this.practiceTitle = res.data.data[0].practiceTitle;
                    for (var i = 0; i < data.length; i++) {
                        var x = { text: '班级1', value: 0 };
                        x.text = data[i].practiceTitle;
                        x.value = data[i].id;
                        this.classInfos.push(x);
                    }
                    console.log(this.classInfos)
                    this.getTasksByClassId();
                }
            }).catch(err => {
                console.log(err);
            })
        },
        changeClass(res) {
            console.log(res)
            //根据班级id获取当前的所有任务信息
            for (var i = 0; i < this.classInfos.length; i++) {
                if (this.classInfos[i].value == res) {
                    this.practiceTitle = this.classInfos[i].text;
                    this.getTasksByClassId();
                }
            }
        },
    },
    computed: {
    },
    mounted() {
        //发送请求 获取该用户的所有班级信息
        this.getShixun();
    },
}
</script>
<style>
.van-dropdown-menu__bar {
    height: 68px;
}
</style>